package com.wl.controller;

import com.wl.exception.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author wolfleong
 * @date 2018-04-17 上午12:21
 **/
@ControllerAdvice
public class ExceptionHandlerController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @ExceptionHandler(BusinessException.class)
    public ModelAndView businessException(BusinessException e){
        final ModelAndView modelAndView = new ModelAndView(e.getPageRouter());
        modelAndView.getModelMap().put("desc",e.getDesc());
        modelAndView.getModelMap().put("isError",true);
        return modelAndView;
    }

    @ExceptionHandler(Exception.class)
    public String businessException(Exception e){
        logger.error("ex",e);
        return "error";
    }
}
